//
// Created by EmFi on 2023/5/21.
//

#ifndef DBMS_TRANSACTIONALDATABASE_H
#define DBMS_TRANSACTIONALDATABASE_H


#include "IndexedDatabase.h"

class TransactionalDatabase : public IndexedDatabase {
private:
    struct TransHead {
        long block_size = sizeof(Operation);
        long length = 0;
    };
    TransHead transHead;
    fstream transConn;
    string transFn;

    bool _open();
    bool _create();
    void _close();
    void record(Operation &op);
public:
    explicit TransactionalDatabase(const string &fn);
    ~TransactionalDatabase() override;

    void printTransaction();

    int insert(Point point) override;
    int insert(list<Point> list) override;
    Point remove(int index) override;
    void clear() override;
    Point update(int index, Point point) override;

    bool rollback(int transIndex);
};


#endif //DBMS_TRANSACTIONALDATABASE_H
